<template>
  <div id="login">
    <div class="logo-container">
<!--      <el-image class="logo-img" :src="titleLogoImg"></el-image>-->

      <h1 class="center-text">copd离院监测系统
      </h1>
    </div>
    <div class="bg-container">
      <div class="bg-img">
        <el-image :src="backGroundImg"/>
      </div>
    </div>
    <div class="container" id="container">
      <div class="form-container sign-in-container">
        <form action="#">
          <div class="form-title">
            <h1 >copd离院监测系统</h1>
<!--            <span>开发版 0.0.1</span>-->
          </div>
          <input  @keyup.enter="login()" type="text" placeholder="账号" v-model="formData.username" />
          <input  @keyup.enter="login()" type="password" placeholder="密码" v-model="formData.password" />
          <div style="display: flex;">
            <div class="loginButton" style="" @click="login()" >登录</div>
<!--            <div class="loginButton" style="background-color: #cccccc;border-color: #cccccc" @click="userRegister()" >注册</div>-->
          </div>
        </form>
      </div>
      <!--        <div class="overlay-container">-->
      <!--          <div class="overlay">-->
      <!--            <div class="overlay-panel overlay-right">-->
      <!--&lt;!&ndash;              <img class="logo" src="../../assets/login/avator.svg" alt="" />&ndash;&gt;-->
      <!--              <p style="color:black">-->
      <!--                这里是宣传语-->
      <!--              </p>-->
      <!--              &lt;!&ndash; <button class="ghost" id="signUp">About Us</button>n &ndash;&gt;-->
      <!--            </div>-->
      <!--          </div>-->
      <!--        </div>-->
    </div>
  </div>
</template>
<script setup>
import { ref,reactive,getCurrentInstance,nextTick } from 'vue'
import router from '../../router';
import user from "@/api/user.js";
import { useAuthStore } from '@/stores/auth.js';
import backGroundImg from '@/assets/login/mappic.png'
import titleLogoImg from '@/assets/img/titleLogo.png'
import {ElMessage} from "element-plus";
import {View} from "@element-plus/icons-vue";
const authStore = useAuthStore();
const formData=ref({
  username: "",
  password: "",
})
const login=()=>{
  const loginDto = {
    username:formData.value.username,
    password:formData.value.password,
  }
  user.login(loginDto).then((res)=>{
    if (res.data.code === 200){
      authStore.setToken(res.data.data.token);
      authStore.setUsername(res.data.data.username);
      authStore.setRole(res.data.data.role);
      authStore.setUserId(res.data.data.id);
      ElMessage.success("登录成功")
      router.push("/index/mainIndex")
    }else{
      ElMessage.error(res.data.msg)
    }
  }).catch((err)=>{
  })
}
</script>
<style  scoped lang="scss">
/*设置标题字体*/
.center-text {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left:30px;
}
#login {
  font-family: "Montserrat", sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 100%;
  //background-image: url('@/assets/login/loginBg.png');
  /* margin: -20px 0 50px; */
  background-size: cover;
}
.logo {
  width: 160px;
  height: auto;
}
h1 {
  font-weight: bold;
  margin: 0;
  color: #028370;
}

p {
  font-size: 14px;
  font-weight: bold;
  line-height: 20px;
  letter-spacing: 0.5px;
  margin: 20px 0 30px;
}

span {
  font-size: 12px;
  color: #028370;
}

a {
  color: #fff;
  font-size: 14px;
  text-decoration: none;
  margin: 15px 0;
}

.container {
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  position: absolute;
  overflow: hidden;
  width: 30%;
  max-width: 384px;
  min-height: 480px;
  opacity: 0.8;
  right: 15%;
  transform: translateX(15%);
}

.form-container form {
  background: rgba(255, 255, 255, 1);
  display: flex;
  flex-direction: column;
  padding: 0 50px;
  height: 100%;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.social-container {
  margin: 20px 0;
}

.social-container a {
  border: 1px solid #ddd;
  border-radius: 50%;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  margin: 0 5px;
  height: 40px;
  width: 40px;
}

.form-container input {
  background: #eee;
  border: none;
  padding: 12px 15px;
  margin: 8px 0;
  width: 100%;
}

.loginButton {
  cursor: pointer;
  border-radius: 20px;
  /* border: 1px solid #ff4b2b;
  background: #ff4b2b; */
  /* border: 1px solid #fa8817;
  background: #fa8817; */
  border: 1px solid #1BBFB4;
  background: #1BBFB4;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  padding: 10px 30px;
  margin-top: 20px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: transform 80ms ease-in;
}

input[type="text"] {
  width: 240px;
  text-align: center;
  background: transparent;
  border: none;
  border-bottom: 1px solid #000000;
  font-family: "PLay", sans-serif;
  font-size: 16px;
  font-weight: bold;
  padding: 10px 0;
  transition: border 0.5s;
  outline: none;
  color: black;
}

input[type="password"] {
  width: 240px;
  text-align: center;
  background: transparent;
  border: none;
  border-bottom: 1px solid #000000;
  font-family: "PLay", sans-serif;
  font-size: 16px;
  font-weight: bold;
  padding: 10px 0;
  transition: border 0.5s;
  outline: none;
  color: black;
}

input[type="email"] {
  width: 240px;
  text-align: center;
  background: transparent;
  border: none;
  border-bottom: 1px solid #fff;
  font-family: "PLay", sans-serif;
  font-size: 16px;
  font-weight: 200;
  padding: 10px 0;
  transition: border 0.5s;
  outline: none;
  color: #fff;
}

.loginButton:active {
  transform: scale(0.95);
}

.loginButton:focus {
  outline: none;
}

.loginButton.ghost {
  //background: transparent;
  /* border-color: #fa8817;
  background-color: #fa8817; */
  border-color: #1BBFB4;
  background-color: #1BBFB4;
  margin: 0;
}

.form-container {
  position: absolute;
  top: 0;
  height: 100%;
  transition: all 0.6s ease-in-out;
}

.sign-in-container {
  left: 0;
  width: 100%;
  z-index: 2;
}

.sign-up-container {
  left: 0;
  width: 50%;
  z-index: 1;
  opacity: 0;
}
.form-title{
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20%;
  flex-direction: column;
}
.overlay-container {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  overflow: hidden;
  transition: transform 0.6s ease-in-out;
  z-index: 100;
}

.overlay {
  background: transparent;
  background: linear-gradient(to right, #ff4b2b, #ff416c) no repeat 0 0 / cover;
  color: #fff;
  position: absolute;
  left: -100%;
  height: 100%;
  width: 200%;
  transform: translateX(0);
  transition: transform 0.6s ease-in-out;
}

.overlay-panel {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 40px;
  height: 100%;
  width: 50%;
  text-align: center;
  transform: translateX(0);
  transition: transform 0.6s ease-in-out;
}

.overlay-right {
  right: 0;
  transform: translateX(0);
}
.logo-container{
  background-color:white;
  position: relative;
  width: 100%;  /* 根据需要调整父容器的宽度 */
  height: 10%;
  overflow: hidden;  /* 确保超出部分被隐藏 */
  display: flex;

}
.logo-img {

}
.logo-img img{
  width: 100%; /* 图片宽度适应容器 */
  height: 100%; /* 图片高度适应容器 */
  object-fit: contain; /* 保持图片的宽高比 */
}
.bg-container{
  background-color: #EDF7F6;
  width: 100%;
  height: 80%;
  margin-bottom: auto;
  display: flex;
  align-items: center;
  position: relative;
  overflow: hidden;  /* 确保超出部分被隐藏 */
}
.bg-img {
  width: 90%;
  height: 90%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.bg-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;  /* 确保图片按比例缩放 */
}
</style>